#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<string>

using namespace std;

#include"string.h"

void test_string1()
{
	std::string s1("hello world");
	cout << s1.c_str() << endl;

	std::string s2;
	cout << s2.c_str() << endl;

	for (size_t i = 0; i < s1.size(); i++)
	{
		s1[i]++;
	}
	cout << endl;

	for (size_t i = 0; i < s1.size(); i++)
	{
		cout << s1[i] << " ";
	}
	cout << endl;

	const bit::string s3("hello world");
	//s3[0];

	//bit::string::iterator cit = s3.begin();
	auto cit = s3.begin();
	while (cit!=s3.end())
	{
		//*cit += 1;

		cout << *cit << " ";
		++cit;
	}
	cout << endl;

	for (auto ch : s1)
	{
		cout << ch << " ";
	}
	cout << endl;
}

void test_string2()
{
	std::string s1("hello world");
	cout << s1.c_str() << endl;

	s1.push_back(' ');
	s1.push_back('#');
	s1.append("hello bit");
	cout << s1.c_str() << endl;

	std::string s2("hello world");
	cout << s2.c_str() << endl;

	s2 += ' ';
	s2 += '#';
	s2 += "hello bit";
	cout << s2.c_str() << endl;
}

void test_string3()
{
	bit::string s1("hello world");
	cout << s1.c_str() << endl;

	s1.insert(5, 3, '#');
	cout << s1.c_str() << endl;

	s1.insert(0, 3, '#');
	cout << s1.c_str() << endl;

	bit::string s2("hello world");
	s2.insert(5, "%%%%");
	cout << s2.c_str() << endl;
}

void test_string4()
{
	bit::string s1("helloworld");
	cout << s1.c_str() << endl;

	s1.erase(5, 3);
	cout << s1.c_str() << endl;

	s1.erase(5, 30);
	cout << s1.c_str() << endl;

	s1.erase(2);
	cout << s1.c_str() << endl;
}

void test_string5()
{
	// 2118
	bit::string url = "ftp://www.baidu.com/?tn=65081411_1_oem_dg";

	size_t pos1 = url.find("://");
	if (pos1 != bit::string::npos)
	{
		bit::string protocol = url.substr(0, pos1);
		cout << protocol.c_str() << endl;
	}

	size_t pos2 = url.find('/', pos1 + 3);
	if (pos2 != bit::string::npos)
	{
		bit::string domain = url.substr(pos1 + 3, pos2 - (pos1 + 3));
		bit::string uri = url.substr(pos2 + 1);

		cout << domain.c_str() << endl;
		cout << uri.c_str() << endl;
	}
}

int main()
{
	//test_string1();
	//test_string2();
	//test_string3();
	//test_string4();
	test_string5();
	return 0;
}
